#include "student.h"
#include <iostream>
#include <cstring>

struct studentPrivate
{
    studentPrivate(int age,const char * name):grade(16),age(age)
    {
        int len = strlen(name);
        this->name = new char[len+1];
        strcpy(this->name,name);
    };

    ~studentPrivate()
    {
        delete name;
    };

    studentPrivate(studentPrivate &stu);
    char *name;
    int age;
    const int grade;
};


studentPrivate::studentPrivate(studentPrivate &stu):grade(stu.grade)
{
    age = stu.age;
    name = new char[strlen(stu.name)+1];
    strcpy(name,stu.name);
}

int student::count = 0;

student::student(const char *name, int age)
{
    p = new studentPrivate(age,name);
    count++;
    printf("create a student!\n");
}

student::student(student &stu)
{
    printf("student(student &stu)\n");
    p = new studentPrivate(*stu.p);
}

void student::Print()
{
    printf("name : %s  age : %d  grade : %d\n",p->name,p->age,p->grade);
}

student::~student()
{
    count--;
    printf("kill a student!\n");
    delete p;
}

void student::func()
{
    printf("static func()! count : %d\n",count);
}